//
//  HHOneController.m
//  Flower
//
//  Created by 花花 on 2016/12/6.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHOneController.h"
#import "HHScrollPageView.h"
#import "HHTabController.h"

@interface HHOneController ()<HHScrollPageViewDelegate>
@property(strong, nonatomic)NSArray<NSString *> *titles;
@end

@implementation HHOneController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.automaticallyAdjustsScrollViewInsets = NO;
    HHSegmentStyle *style =[[HHSegmentStyle alloc]init];
    
    style.scaleTitle = YES;
    style.gradualChangeTitleColor = YES;
    
    self.titles = @[@"新闻头条",
                    @"国际要闻",
                    @"体育",
                    @"中国足球",
                    @"汽车",
                    @"囧途旅游",
                    @"幽默搞笑",
                    @"视频",
                    @"无厘头",
                    @"美女图片",
                    @"今日房价",
                    @"头像",
                    ];
    
    HHScrollPageView *scroll =[[HHScrollPageView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height-64) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    
    [self.view addSubview:scroll];
    
    
}
/** 将要显示的子页面的总数 */
-(NSInteger)numberOfChildViewControllers{

    return self.titles.count;
}



/** 获取到将要显示的页面的控制器
 * -reuseViewController : 这个是返回给你的controller, 你应该首先判断这个是否为nil, 如果为nil 创建对应的控制器并返回, 如果不为nil直接使用并返回
 * -index : 对应的下标
 */
- (UIViewController<HHScrollPageViewChildDelegate> *)childViewController:(UIViewController<HHScrollPageViewChildDelegate> *)reuseViewController forIndex:(NSInteger)index{

  
    UIViewController<HHScrollPageViewChildDelegate> *childVc = reuseViewController;
    if (!childVc) {
        childVc = [[HHTabController alloc]init];
        childVc.title = self.titles[index];
    }
    return childVc;
}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllWillAppear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%zd ---将要出现",index);
}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllDidAppear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%zd ---已经出现",index);
}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllWillDisappear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%zd ---将要消失",index);
    
}


- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllDidDisappear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%zd ---已经消失",index);
    
}
@end
